// app.ts
App<IAppOption>({
  globalData: {},
  xh: {
    sysTitle:"粮库害虫诱捕系统",
    copyRight:"中科芯禾",
    logoUrl:"https://ai.seedlight.cn:31000/iot-web-manage/img/home-logo.8be66afc.svg",
    userInfo:{},
    grain:{},
    config:{
      apiUrl:"https://ai.seedlight.cn:31000/api/seedlight/"
    }
  },
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        console.log(res.code)
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      },
    })
  },
  callApi( apiPath , apiPs){
    var me = this;
    return new Promise((success, faild)=>{
      try {
        var apiUrl = me.xh.config.apiUrl+ apiPath;
        wx.request({
          url:apiUrl,
          method: "POST",
          data:apiPs||{},   
        })
      } catch (ee) {
        console.log(ee);
        success();
      }
    })
  }
})